<?php
class AlbumsController extends AlbumAppController {
	public $uses = array ('Album.Album' );
	
	/**
	 * 相册列表
	 * @author lj@gootop.net  
	 * @Date 2012-11-16
	 * @param
	 * @return
	 *
	 */
	function admin_index() {
		$this->paginate = array(
				'Album' => array(
						//'conditions' => array('Album.user_id'=>$this->Auth->user('id')),
						'order' => 'Album.id DESC',
						) 
				);
		$albumList = $this->paginate();
		$this->set ( 'albumList', $albumList );
	}
	/**
	 * 添加相册
	 * @author lj@gootop.net  
	 * @Date 2012-11-16
	 * @param
	 * @return
	 *
	 */
	function add() {
		if (! empty ( $this->data )) {
			if ($this->Album->save ( $this->data )) {
				$this->Session->setFlash ( '添加成功！' );
				$this->redirect ( array (
						'action' => 'index' 
				) );
			}
		}
	}
	/**
	 * 编辑相册信息
	 * @author lj@gootop.net  
	 * @Date 2012-11-16
	 * @param
	 * @return
	 */
	function edit($id = NULL) {
		$this->Album->id = $id;
		if (empty ( $this->data )) {
			$this->data = $this->Album->read ();
		} else {
			$album_info = $this->Album->getAlbumById ( $id );
			if ($album_info ['Album'] ['user_id'] == $this->Auth->user ( 'id' )) {
				if ($this->Album->save ( $this->data )) {
					$this->Session->setFlash ( '更新成功.' );
					$this->redirect ( array (
							'action' => 'index' 
					) );
				}
			}
		}
	}
	/**
	 * 删除相册
	 * @author lj@gootop.net  
	 * @Date 2012-11-16
	 * @param
	 * @return
	 */
	function delete($id) {
		$chkAblumDel = $this->Album->ChkAblumDel ( $this->Auth->user ( 'id' ), $id );
		if ($chkAblumDel ['flag']) {
			$this->Album->delete ( $id );
		}
		$this->Session->setFlash ( $chkAblumDel ['message'] );
		$this->redirect ( array (
				'action' => 'index' 
		) );
	}
	/**
	 * 会员相册 option 列表
	 * @author lj@gootop.net  
	 * @Date 2012-12-3
	 * @param
	 * @return 
	 */
	function albumListOption(){
		return $this->Album->getAlbumList($this->Auth->user('id'));
	}
}
